<template>
	<view class="tab-control">
		<view v-for="(item,index) in titles" :key="index" class="tab-control-item" :class="{active: index === currentIndex}" @click="tabClick(index)">
			<text>{{item.title}}</text>
			<view class="tab-control-item-aomunt" v-if="item.amount > 0">{{item.amount}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			titles: {
				type: Array,
				default () {
					return [];
				}
			}
		},
		data() {
			return {
				currentIndex: 0
			};
		},
		methods: {
			tabClick(index) {
				this.currentIndex = index;
				this.$emit("tabClick", index);
			}
		}
	}
</script>

<style lang="less">
	.tab-control {
		display: flex;
		text-align: center;
		font-size: 12px;
		height: 40px;
		line-height: 40px;
		background-color: #fff;
		
		.tab-control-item {
			position: relative;
			flex: 1;
			
			text{
				padding: 5px;
			}
			
			.tab-control-item-aomunt{
				position: absolute;
				right: 0;
				top: 0;
				width: 30upx;
				height: 30upx;
				line-height: 30upx;
				color: #FFFFFF;
				border-radius: 50%;
				background-color: #007AFF;
			}
			
		}
		
		.active {
			color: #007AFF;
			
			text{
				border-bottom: 2px solid #007AFF;
			}
			
		}
		
	}
</style>
